package cn.allinmd.indi.applymodelxian.authenticate;

import android.content.Context;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.test.ApplicationTestCase;
import android.util.Log;

import cn.allinmd.indi.applymodelxian.comm.app.BaseApplication;
import cn.allinmd.indi.applymodelxian.model.authenticate.bizz.IAuthModel;
import cn.allinmd.indi.applymodelxian.model.authenticate.bizz.impl.Auth2Impl;
import cn.allinmd.indi.applymodelxian.model.authenticate.entity.User;

/**
 *
 *
 * @author: XianXueLiang
 * @date: 2016/6/22
 */
public class CRUDTest extends ApplicationTestCase<BaseApplication> {
    private static final String TEST_TAG = CRUDTest.class.getSimpleName();
    private BaseApplication mApplication;

    public CRUDTest(){
        super(BaseApplication.class);
    }

    ////--------basic features test

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        createApplication();
        mApplication = getApplication();
    }

    public void testInsert(){
        IAuthModel<User> authModel = new Auth2Impl(mApplication.getContext());
        User user = new User();
        user.setUsername("XianXueLiang");
        user.setPassword("xianxueliang123");
        user.setEmail("xianxueliang@allinmd.cn");
        user.setEmailVerified(false);
        user.setMobilePhoneNumber("18500516148");
        user.setMobilePhoneNumberVerified(false);
        authModel.register(user, new IAuthModel.OnAuthStateListener<User>() {
            @Override
            public void success(User user, String accessToken) {
                Log.i(TEST_TAG, "success: ");
            }

            @Override
            public void failure(int code, String msg) {
                Log.i(TEST_TAG, "failure: code:"+code+"msg:"+msg);
            }
        });
        try {
            Thread.sleep(Integer.MAX_VALUE);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
    public void testSignIn(){
        Context context = mApplication.getContext();
        IAuthModel<User> authModel = new Auth2Impl(context);
        TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String deviceId = manager.getDeviceId();
        String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
        //UUID uuid = UUID.fromString(deviceId);
        //String uuidDevices = uuid.toString();
        authModel.login("XianXueLiang", "xianxueliang123", deviceId, new IAuthModel.OnAuthStateListener<User>() {
            @Override
            public void success(User user, String accessToken) {
                Log.d(TEST_TAG, "success: user:"+user.toString()+"\n,accessToken:"+accessToken);
            }

            @Override
            public void failure(int code, String msg) {
                Log.i(TEST_TAG, "failure: code:"+code+"msg:"+msg);
            }
        });
        try {
            Thread.sleep(Integer.MAX_VALUE);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
